<%@page import="support.*, java.util.*" %>
<HTML>
<HEAD><TITLE>Specialization Analytics Page</TITLE></HEAD>
<BODY>
Choose the specialization you want to check : 
<p>
 <%-- Import the java.sql package --%>
 <%@ page import="java.sql.*"%>
 <%-- -------- Open Connection Code -------- --%>
 <%
            
   Connection conn = null;
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
    // Registering Postgresql JDBC driver with the DriverManager
    Class.forName("org.postgresql.Driver");
   // Open a connection to the database using DriverManager
   conn = DriverManager.getConnection(
     "jdbc:postgresql://localhost/admissions?" +
        "user=postgres&password=27428572");
 %>
<%
 // Begin transaction
      conn.setAutoCommit(false);
 %>
<FORM METHOD=GET ACTION="application.jsp">
<%
Statement stmt = conn.createStatement();
Statement stmt2 = conn.createStatement();
support s = new support();
String path4 = config.getServletContext().getRealPath("specializations.txt");
Vector specialization = s.getSpecializations(path4);
ResultSet spec = stmt.executeQuery("SELECT name FROM specializations");

while (spec.next())
{
out.println(spec.getString(1));
ResultSet specId = stmt2.executeQuery("SELECT id FROM specializations WHERE name = '"+spec.getString(1)+"'");
int count = 0;
if(specId.next())
{
String input = "SELECT id FROM student WHERE spec = '"+specId.getInt(1)+"'";
rs = stmt2.executeQuery(input); 
}
while(rs.next())
	count++;
out.println("             ");

%>
<a href="application.jsp?specialization=<%=spec.getString(1)%>"><%=count%></a>

<%
out.println("<br>");
}
 }

			catch (SQLException e){
				throw new RuntimeException(e);
			}

finally{
		if(rs != null){
					try{ 
						rs.close();
					}catch (SQLException e){ }
					rs = null;
				}
				if(pstmt != null){
					try{
						pstmt.close();
					}catch(SQLException e){}
					pstmt = null;
				}
				if(conn != null){
					try{
						conn.close();
					}catch (SQLException e) { }
					conn = null;
				}

		}

%>

</SELECT>
</FORM>
</BODY>
</HTML>
